package com.dr.common.ution;

// public class DateUtil {

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;

/**
 * @author Tan Tailiang
 * 创建日期：2006-4-21
 * 类说明：<p>对日期进行操作类</p>
 */
public class DateUtil {

    // 本地化日期时间
    private static final Locale     locale                 = Locale.SIMPLIFIED_CHINESE;
    // 设置日期时间格式为年-月-日
    private static final DateFormat timeFormat             = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
    // 实例化日历工具类
    private static final Calendar   calendar               = Calendar.getInstance();
    public static final long        SECOND                 = 1000L;
    public static final long        MINUTE                 = 60 * SECOND;
    public static final long        HOUR                   = 60 * MINUTE;
    public static final long        DAY                    = 24 * HOUR;
    public static final long        WEEK                   = 7 * DAY;

    private static DateFormat       dateTimeFormatter      = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    private static DateFormat       dateFormatter          = new SimpleDateFormat("yyyy-MM-dd");

    private static final long       MSECONDS_OF_ONE_DAY    = 60 * 60 * 1000 * 24;

    private static final long       MSECONDS_OF_ONE_MINUTE = 60 * 1000;

    private static final String[]   days                   = { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天" };

    private static DateFormat       dateTimeFormatter1     = new SimpleDateFormat("HHmmss");
    private static DateFormat       dateTimeFormatter2     = new SimpleDateFormat("yyyyMMddHHmmss");
    private static DateFormat       dateTimeFormatter3     = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

    /**
     * yyyyMMddHHmmss
     */
    private static DateFormat       dateTimeFormatter4     = new SimpleDateFormat("yyyyMMddHHmmss");

    /**
     * 获取当前时间 yyyyMMddHHmmss
     * @return
     */
    public static String now() {
        return dateTimeFormatter4.format(new Date()).trim();
    }

    /**
     * write by steven.shi 2004-10-18
     * 方法说明：<p>取得指定月份的第一天</p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param year
     * @param month
     * @return
     */
    public static Date getFirstDayOfMonth(int year, int month) {
        Calendar cl = Calendar.getInstance();
        cl.set(Calendar.YEAR, year);
        cl.set(Calendar.MONTH, month - 1);
        cl.set(Calendar.DAY_OF_MONTH, 1);
        return cl.getTime();
    }

    /**
     * 
     * 方法说明：<p></p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param date
     * @return
     */
    public static String dateTimeToString1(Date date) {
        if (date == null)
            return "";
        return dateTimeFormatter1.format(date).trim();

    }

    /**
     * 
     * 方法说明：<p></p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param date
     * @return
     */
    public static String dateTimeToString3(Date date) {
        if (date == null)
            return "";
        return dateTimeFormatter3.format(date).trim();

    }

    /**
     * 
     * 方法说明：<p>取得指定月份的最后一天</p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param year
     * @param month
     * @return
     */
    public static Date getLastDayOfMonth(int year, int month) {
        Calendar cl = Calendar.getInstance();
        cl.set(Calendar.YEAR, year);
        cl.set(Calendar.MONTH, month - 1);
        cl.set(Calendar.DAY_OF_MONTH, cl.getActualMaximum(Calendar.DAY_OF_MONTH));
        return cl.getTime();
    }

    /**
     * 
     * 方法说明：<p>将String型的日期转换成Date型</p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param dateString
     * @return
     * @throws ParseException
     */
    public static Date stringToDateTime(String dateString) throws ParseException {
        Date date = dateTimeFormatter.parse(dateString);
        return date;
    }

    /**
     * 
     * 方法说明：<p>将String型的日期转换成Date型</p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param dateString
     * @return
     * @throws ParseException
     */
    public static Date stringToDateTime3(String dateString) throws ParseException {
        Date date = dateTimeFormatter3.parse(dateString);
        return date;
    }

    /**
     * 
     * 方法说明：<p>将String型的日期转换成Date型</p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param dateString
     * @param format
     * @param locale
     * @return
     * @throws ParseException
     */
    public static Date stringToDate(String dateString, String format, Locale locale) throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat(format, locale);
        return formatter.parse(dateString);
    }

    /**
     * write by steven.shi 2004-10-18
     * 方法说明：<p></p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param orgDate
     * @return
     */
    public static Date convertOrgDate(String orgDate) {
        Calendar cl = Calendar.getInstance();
        cl.set(Calendar.YEAR, Integer.parseInt(orgDate.substring(0, 4)));
        cl.set(Calendar.MONTH, Integer.parseInt(orgDate.substring(5, 7)) - 1);
        cl.set(Calendar.DAY_OF_MONTH, Integer.parseInt(orgDate.substring(8, 10)));
        cl.set(Calendar.HOUR_OF_DAY, 0);
        cl.set(Calendar.MINUTE, 0);
        cl.set(Calendar.SECOND, 0);
        return cl.getTime();
    }

    /**
     * write by steven.shi 2004-10-18
     * 方法说明：<p></p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param orgDate
     * @return
     */
    public static Date convertRealTimeDate(String orgDate) {
        Calendar cl = Calendar.getInstance();
        cl.set(Calendar.YEAR, Integer.parseInt(orgDate.substring(0, 4)));
        cl.set(Calendar.MONTH, Integer.parseInt(orgDate.substring(5, 7)) - 1);
        cl.set(Calendar.DAY_OF_MONTH, Integer.parseInt(orgDate.substring(8, 10)));
        return cl.getTime();
    }

    /**
     * Get the Next Date Write by Jeffy pan 2004-10-21
     * Date Format:YYYY-MM-DD YYYY:M:D YYYY/M/DD
     * 方法说明：<p></p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param date
     * @return
     */
    public static String getNextDate(String date) {

        Calendar cd = Calendar.getInstance();
        StringTokenizer token = new StringTokenizer(date, "-/ :");
        if (token.hasMoreTokens()) {
            cd.set(Calendar.YEAR, Integer.parseInt(token.nextToken()));
        }
        else {
            cd.set(Calendar.YEAR, 1970);
        }
        if (token.hasMoreTokens()) {
            cd.set(Calendar.MONTH, Integer.parseInt(token.nextToken()) - 1);
        }
        else {
            cd.set(Calendar.MONTH, 0);
        }
        if (token.hasMoreTokens()) {
            cd.set(Calendar.DAY_OF_MONTH, Integer.parseInt(token.nextToken()));
        }
        else {
            cd.set(Calendar.DAY_OF_MONTH, 1);
        }
        if (token.hasMoreTokens()) {
            cd.set(Calendar.HOUR_OF_DAY, Integer.parseInt(token.nextToken()));
        }
        else {
            cd.set(Calendar.HOUR_OF_DAY, 0);
        }
        if (token.hasMoreTokens()) {
            cd.set(Calendar.MINUTE, Integer.parseInt(token.nextToken()));
        }
        else {
            cd.set(Calendar.MINUTE, 0);
        }
        if (token.hasMoreTokens()) {
            cd.set(Calendar.SECOND, Integer.parseInt(token.nextToken()));
        }
        else {
            cd.set(Calendar.SECOND, 0);
        }
        if (token.hasMoreTokens()) {
            cd.set(Calendar.MILLISECOND, Integer.parseInt(token.nextToken()));
        }
        else {
            cd.set(Calendar.MILLISECOND, 0);
        }

        long nextTime = cd.getTimeInMillis() + 24 * 60 * 60 * 1000;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(new Date(nextTime));
    }

    /**
     * Get the Next Date Write by Jeffy pan 2004-10-21
     * Date Format:(YYYY-MM-DD) (YYYY:M:D HH:MM:SS)  (YYYY/M/DD hh:MM) 
     * 方法说明：<p></p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param date
     * @return
     */
    public static Date stringToDate(String date) {
        if (date == null)
            return null;

        Calendar cd = Calendar.getInstance();
        StringTokenizer token = new StringTokenizer(date, "-/ :");
        if (token.hasMoreTokens()) {
            cd.set(Calendar.YEAR, Integer.parseInt(token.nextToken()));
        }
        else {
            cd.set(Calendar.YEAR, 1970);
        }
        if (token.hasMoreTokens()) {
            cd.set(Calendar.MONTH, Integer.parseInt(token.nextToken()) - 1);
        }
        else {
            cd.set(Calendar.MONTH, 0);
        }
        if (token.hasMoreTokens()) {
            cd.set(Calendar.DAY_OF_MONTH, Integer.parseInt(token.nextToken()));
        }
        else {
            cd.set(Calendar.DAY_OF_MONTH, 1);
        }
        if (token.hasMoreTokens()) {
            cd.set(Calendar.HOUR_OF_DAY, Integer.parseInt(token.nextToken()));
        }
        else {
            cd.set(Calendar.HOUR_OF_DAY, 0);
        }
        if (token.hasMoreTokens()) {
            cd.set(Calendar.MINUTE, Integer.parseInt(token.nextToken()));
        }
        else {
            cd.set(Calendar.MINUTE, 0);
        }
        if (token.hasMoreTokens()) {
            cd.set(Calendar.SECOND, Integer.parseInt(token.nextToken()));
        }
        else {
            cd.set(Calendar.SECOND, 0);
        }
        if (token.hasMoreTokens()) {
            cd.set(Calendar.MILLISECOND, Integer.parseInt(token.nextToken()));
        }
        else {
            cd.set(Calendar.MILLISECOND, 0);
        }

        return cd.getTime();
    }

    /**
     * Get the Next Date Write by Jeffy pan 2004-10-21
     * Date Format:(YYYY-MM-DD) (YYYY:M:D HH:MM:SS)  (YYYY/M/DD hh:MM) 
     * 方法说明：<p></p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param date
     * @return
     */
    public static String dateToString(Date date) {
        if (date == null)
            return "";
        return dateFormatter.format(date).trim();

    }

    /**
     * 
     * 方法说明：<p></p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param date
     * @return
     */
    public static String dateTimeToString2(Date date) {
        if (date == null)
            return "";
        return dateTimeFormatter2.format(date).trim();

    }

    /**
     *  Get the Next Date Write by Jeffy pan 2004-10-21
     * Date Format:(YYYY-MM-DD) (YYYY:M:D HH:MM:SS)  (YYYY/M/DD hh:MM) 
     */
    public static String dateToString(Date date, String format, Locale locale) {

        SimpleDateFormat formatter = new SimpleDateFormat(format, locale);
        return formatter.format(date).trim();
    }

    /**
     * 
     * 方法说明：<p></p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param date
     * @return
     */
    public static String dateTimeToString(Date date) {
        if (date == null)
            return "";
        return dateTimeFormatter.format(date).trim();

    }

    /*
     * Get the Next Date Write by Jeffy pan 2004-10-21
     * Date Format:(YYYY-MM-DD) (YYYY:M:D HH:MM:SS) (YYYY/M/DD hh:MM)
     */
    public static String dateToString(Date date, String format) {

        SimpleDateFormat formatter = new SimpleDateFormat(format);
        return formatter.format(date).trim();
    }

    /*
     * Get the Next Date Write by Jeffy pan 2004-10-21
     * Date Format:(YYYY-MM-DD) (YYYY:M:D HH:MM:SS) (YYYY/M/DD hh:MM)
     */
    public static int getDays(String fromDate, String endDate) {

        long from = stringToDate(fromDate).getTime();
        long end = stringToDate(endDate).getTime();

        return (int) ((end - from) / (24 * 60 * 60 * 1000)) + 1;
    }

    /**
     * 
     * 方法说明：<p></p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param fromDate
     * @param endDate
     * @return
     */
    public static int getDays(Date fromDate, Date endDate) {

        long from = fromDate.getTime();
        long end = endDate.getTime();

        return (int) ((end - from) / (24 * 60 * 60 * 1000)) + 1;
    }

    /**
     * 
     * 方法说明：<p></p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param startDate
     * @param endDate
     * @return
     */
    public static String getTakeTime(Date startDate, Date endDate) {
        int minute = 0;
        try {
            minute = (int) (endDate.getTime() - startDate.getTime()) / (1000 * 60);
            return String.valueOf(minute);
        }
        catch (Exception e) {
            return "";
        }

    }

    /*
     * 获取月份的第一天
     * written by Sammy: 2004-10-26
     */
    public static int getFirstDateOfMonth(int year, int month) {

        Calendar cl = Calendar.getInstance();
        cl.set(Calendar.YEAR, year);
        cl.set(Calendar.MONDAY, month - 1);
        return cl.getActualMinimum(Calendar.DAY_OF_MONTH);
    }

    /*
     * 获取月份的最后一天
     * written by Sammy: 2004-10-26
     */
    public static int getLastDateOfMont(int year, int month) {
        Calendar cl = Calendar.getInstance();
        cl.set(Calendar.YEAR, year);
        cl.set(Calendar.MONDAY, month - 1);
        return cl.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    /**
     * 
     * 方法说明：<p></p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param date
     * @return
     */
    public static java.sql.Date convertUtilDateToSQLDate(java.util.Date date) {
        if (date == null)
            return null;
        Calendar cl = Calendar.getInstance();
        cl.setTime(date);
        java.sql.Date jd = new java.sql.Date(cl.getTimeInMillis());
        return jd;
    }

    /**
     * 
     * 方法说明：<p></p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param dateString
     * @return
     */
    public static java.sql.Date convertStringToSQLDate(String dateString) {
        return (convertUtilDateToSQLDate(stringToDate(dateString)));
    }

    public static java.sql.Date convertToSQLDateWithoutTime(java.util.Date date) {
        String dateString = dateFormatter.format(date);
        return convertStringToSQLDate(dateString);
    }

    /**
     * get offset to the previous sunday from the specific date
     * @param from the specific start date
     * @param from the specific end date
     * @return offset to the previous sunday
     * @throws ParseException
     */
    public static List getAllSundays(Date from, Date to) {
        List sundayList = new ArrayList();
        int offset = getOffsetToNextSunday(from);
        Date firstSunday = addDate(from, offset);
        Date current = firstSunday;
        while (current.compareTo(to) <= 0) {
            sundayList.add(current);
            current = addDate(current, 7);
        }
        return sundayList;
    }

    /**
     * get offset to the next sunday from the specific date
     * @param date the specific date
     * @return offset to the next sunday
     * @throws ParseException
     */
    public static int getOffsetToNextSunday(Date date) {
        if (getDayOfWeek2(date) == 1)
            return 0;
        return 8 - getDayOfWeek2(date);
    }

    /**
     * get day index of a week for the specific date
     * @param date the specific date
     * @return day index of a week,Mon. is 1,Tues. is 2,Wed. is 3,Thurs. is 4,Fri. is 5,Sat. is 6,Sun. is 7
     * @throws ParseException
     */
    public static int getDayOfWeek(Date date) {
        if (date == null)
            return 0;
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int result = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (result == 0)
            result = 7;
        return result;
    }

    /**
     * get day index of a week for the specific date
     * @param date the specific date
     * @return day index of a week,Sun. is 1,Mon. is 2,Tues. is 3,Wed. is 4,Thurs. is 5,Fri. is 6,Sat. is 7
     * @throws ParseException
     */
    public static int getDayOfWeek2(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.DAY_OF_WEEK);
    }

    /**
     * get day index of a week for the specific date
     * @param date the specific date
     * @return day index of a week,Sun. is 1,Mon. is 2,Tues. is 3,Wed. is 4,Thurs. is 5,Fri. is 6,Sat. is 7
     * @throws ParseException
     */
    public static String getDayOfWeek3(Date date) {
        int day = getDayOfWeek(date);
        return days[day - 1];
    }

    /**
     * add days to the specific date
     * @param days day count to be added
     * @return java.util.Date object after add days
     * @throws ParseException
     */
    public static Date addDate(Date sourceDate, int days) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(sourceDate);
        calendar.add(Calendar.DATE, days);
        return calendar.getTime();
    }

    /**
     * add days to the specific date
     * @return java.util.Date object after add days
     * @throws ParseException
     */
    public static Date addHour(Date sourceDate, int hours) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(sourceDate);
        calendar.add(Calendar.HOUR, hours);
        return calendar.getTime();
    }

    /**
     * add second to the specific date
     * @return java.util.Date object after add seconds
     * @throws ParseException
     */
    public static Date addMinute(Date sourceDate, int Minute) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(sourceDate);
        calendar.add(Calendar.MINUTE, Minute);
        return calendar.getTime();
    }

    /**
     * add second to the specific date
     * @return java.util.Date object after add seconds
     * @throws ParseException
     */
    public static Date addSecond(Date sourceDate, int second) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(sourceDate);
        calendar.add(Calendar.SECOND, second);
        return calendar.getTime();
    }

    /**
     * add days to the specific date
     * @param days day count to be added
     * @return java.util.Date object after add days
     * @throws ParseException
     */
    public static Date addDate(String stringDate, int days) {
        Date sourceDate = stringToDate(stringDate);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(sourceDate);
        calendar.add(Calendar.DATE, days);
        return calendar.getTime();
    }

    /**
     * @return
     */
    public static String addOneDay(Date sourceDate) {

        Date newDate = addDate(sourceDate, 1);
        return dateToString(newDate);

    }

    /**
     * 
     * @param from
     * @param to
     * @return
     * @throws ParseException
     */
    public static long subDate(Date from, Date to) throws ParseException {
        long value = Math.abs(to.getTime() - from.getTime());
        return value / MSECONDS_OF_ONE_DAY;
    }

    public static long subDateMinute(Date from, Date to) throws ParseException {
        long value = Math.abs(to.getTime() - from.getTime());
        return value / MSECONDS_OF_ONE_MINUTE;
    }

    /**
     * <br>Author：zy_fu<br>
     * <br>Date：2007-7-20<br>
     * <br>Mender：<br>
     * <br>Date：YYYY-MM-DD<br>
     * <br>Version:<br>
     * <p>计算两个时间的间隔
     *
     * <p>@param from
     * <p>@param to
     * <p>@param unitInMSecond 时间间隔的单位，1000=秒，60*1000=分钟，60*60*1000=小时...
     * <p>@return
     * <p>@throws ParseException
     */
    public static long getTimespan(Date from, Date to, long unitInMSecond) throws ParseException {
        long value = Math.abs(to.getTime() - from.getTime());
        return value / unitInMSecond;
    }

    /**
     * 
     * @param from
     * @param to
     * @return
     * @throws ParseException
     */
    public static long subDate(String from, String to) throws ParseException {
        return subDate(stringToDate(from), stringToDate(to));
    }

    /**
     * 返回时间列表 (startDate, endDate, days[])	 
     * 方法说明：<p></p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param startDate
     * @param endDate
     * @param days
     * @return
     */
    public static List getStringDateList(String startDate, String endDate, int[] days) {

        List dateList = new ArrayList();

        int days2 = DateUtil.getDays(startDate, endDate) - 1;
        Date fromDate2 = DateUtil.stringToDate(startDate);
        Date endDate2 = DateUtil.stringToDate(endDate);

        Calendar cal = Calendar.getInstance();

        for (int i = 0; i < days2; i++) {

            cal.setTime(fromDate2);
            cal.add(Calendar.DATE, i);

            for (int j = 0; j < days.length; j++) {
                // 星期数等于所选的
                if (days[j] == cal.get(Calendar.DAY_OF_WEEK)) {

                    dateList.add(DateUtil.dateToString(cal.getTime()));
                } // if
            } // for

        } // for

        return dateList;
    }

    /**
     * 
     * 方法说明：<p></p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param startDate
     * @param endDate
     * @param days
     * @return
     */
    public static List getDateList(String startDate, String endDate, int[] days) {

        List dateList = new ArrayList();

        int days2 = DateUtil.getDays(startDate, endDate);
        Date fromDate2 = DateUtil.stringToDate(startDate);
        Date endDate2 = DateUtil.stringToDate(endDate);

        Calendar cal = Calendar.getInstance();

        for (int i = 0; i < days2; i++) {

            cal.setTime(fromDate2);
            cal.add(Calendar.DATE, i);

            for (int j = 0; j < days.length; j++) {
                // 星期数等于所选的
                if (days[j] == cal.get(Calendar.DAY_OF_WEEK)) {
                    dateList.add(cal.getTime());
                } // if
            } // for

        } // for

        return dateList;
    }

    /**
     * 
     * 方法说明：<p></p>
     * 创建日期：2006-4-21
     * 创建人： Tan Nailiang
     * @param firstDate
     * @param secondDate
     * @return
     */
    public static int compareDate(Date firstDate, Date secondDate) {
        return firstDate.compareTo(secondDate);
    }

    /**
     * 
     * Author：hxiang_xu<br>
     * Date：2005-7-8<br>
     * Mender：<br>
     * Date：YYYY-MM-DD<br>
     * Version:<br>
     * 返回修改的时间。
     * @param  date - 传入的时间 <code>Date</code>
     * @param field 要修改的时间类型（Calendar.DATE，Calendar.HOUR, ...） <code>in</code>
     * @param field 要修改的数值 <code>int</code>
     * @return Date
     *
     */
    public static Date AddDate(Date date, int field, int amount) {
        Calendar newCalendar = Calendar.getInstance();
        newCalendar.setTime(date);
        newCalendar.add(field, amount);
        return newCalendar.getTime();
    }

    public static int getDayDifference(Date date1, Date date2) {
        Calendar gc1 = Calendar.getInstance();
        Calendar gc2 = Calendar.getInstance();
        gc1.setTime(date1);
        gc2.setTime(date2);

        long millis = gc2.getTimeInMillis() - gc1.getTimeInMillis();
        return Math.abs((int) (millis / 1000 / 24 / 60 / 60));
    }

    /**
     * Returns the difference between the two dates in days.
     * 
     * @param c1
     * @param c2
     * @return
     */
    public static int getDayDifference(Calendar c1, Calendar c2) {
        return getDayDifference(c1.getTime(), c2.getTime());
    }

    /**
     * 获得指定日期范围内所有的日期
     * 
     * @param beginDate 起始日期，格式[yyyyMMdd]
     * @param endDate 截止日期，格式[yyyyMMdd]
     * @return 日期列表
     */
    public static List<String> getDatesBetweenDate(String beginDate, String endDate) {
        List<String> dates = new ArrayList<String>();
        if (beginDate.equals(endDate)) {
            dates.add(beginDate);
        }
        else {
            Date beginDateDt = parseDate(beginDate, "yyyyMMdd", null);
            Date endDateDt = parseDate(endDate, "yyyyMMdd", null);
            int numbs = getBetweenDays(beginDateDt, endDateDt);
            String currentDate = null;
            for (int i = 0; i <= numbs; i++) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(beginDateDt);
                calendar.add(Calendar.DAY_OF_YEAR, i);
                try {
                    currentDate = new SimpleDateFormat("yyyyMMdd").format(calendar.getTime());
                }
                catch (Exception ex) {
                    ex.printStackTrace();
                }
                dates.add(currentDate);
            }
        }
        return dates;
    }

    /**
     * 字符串的日期时间格式化成Date对象
     * 
     * @param dateValue
     * @param dateFormat
     * @param defaultValue
     * @return Date对象
     */
    public static Date parseDate(String dateValue, String dateFormat, Date defaultValue) {
        try {
            return new SimpleDateFormat(dateFormat).parse(dateValue);
        }
        catch (Exception e) {
            return defaultValue;
        }
    }

    /**
     * 两个日期的间隔天数
     * 
     * @param beginDate 起始日期
     * @param endDate 截止日期
     * @return 间隔天数
     */
    public static int getBetweenDays(Date beginDate, Date endDate) {
        return Math.abs(new Long((setTime(endDate, 0, 0, 0).getTime() - setTime(beginDate, 0, 0, 0).getTime()) / DAY).intValue());
    }

    /**
     * 设置时间
     * 
     * @param date 日期实例
     * @param hour 时
     * @param minute 分
     * @param second 秒
     * @return 设置后的日期时间
     */
    public static Date setTime(Date date, int hour, int minute, int second) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.HOUR_OF_DAY, hour);
        cal.set(Calendar.MINUTE, minute);
        cal.set(Calendar.SECOND, second);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }

    public static void main(String[] args) {
        String settleDate = "20170401-20170601";
        String beginSettleDate = null;
        String endSettleDate = null;
        if (settleDate.contains("-")) {
            beginSettleDate = settleDate.substring(0, settleDate.indexOf("-"));
            endSettleDate = settleDate.substring(settleDate.indexOf("-") + 1, settleDate.length());
        }
        List<String> dates = DateUtil.getDatesBetweenDate(beginSettleDate, endSettleDate);
        for (String date : dates) {
            System.out.println(date);
        }
    }

}
